home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / GL / snurb / snurb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.4 KB  |  175 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  * snurb.c
  19.  */
  20.  
  21. #include <gl.h>
  22. #include <device.h>
  23. #include <math.h>
  24. #include <stdio.h>
  25. #include "defines.h"
  26. #include "snurb.h"
  27. #include "data.h"
  28.  
  29. #include "event.h"
  30. #include "light.h"
  31. #include "menu.h"
  32. #include "draw.h"
  33. #include "rotate.h"
  34. #include "control.h"
  35.  
  36.  
  37. /* window information */
  38. long origin_x, origin_y;
  39. long size_x, size_y;
  40. float aspect;
  41.  
  42. Boolean sb_exists=FALSE;
  43.  
  44.  
  45. extern Matrix identity_matrix;
  46.  
  47. void main()
  48. {
  49. foreground();
  50.  
  51.  
  52.     /* initialize everything */
  53.     init_window();
  54.     init_events();
  55.     init_data();
  56.     make_lights();
  57.     init_menus();
  58.     
  59.     /* draw it once, then let the events do everything */
  60.     draw_display();
  61.  
  62.     /* event() looks for the events (as in init_events) and passes 
  63.        them on to the appropriate routines */
  64.     while(TRUE)
  65.         event();
  66. }
  67.  
  68.  
  69. long snurb_window;
  70.  
  71. /* 
  72.  * Opens the window and sets up the graphic mode.
  73.  */
  74. void init_window(void)
  75. {
  76.     snurb_window = winopen("Snurbs");
  77.     doublebuffer();
  78.     RGBmode();
  79.     gconfig();
  80.     
  81.     zbuffer(TRUE); 
  82.     lsetdepth(0, 0x7fffff);
  83.  
  84.     getorigin(&origin_x, &origin_y);
  85.     getsize(&size_x, &size_y);
  86.     aspect = (float)size_x/(float)size_y;
  87.  
  88.     mmode(MVIEWING);
  89.  
  90. #ifdef spaceball    
  91.     sb_exists = sbInit();
  92. #endif
  93. }
  94.  
  95.  
  96.  
  97. /* 
  98.  * Tells event manager what to pay attention to.
  99.  */
  100. void init_events(void)
  101. {
  102.     /* ESC key and WINQUIT quit the program */
  103.     add_event(ANY, ESCKEY, UP, quit, NULL);
  104.     qdevice(ESCKEY);
  105.     add_event(ANY, WINQUIT, ANY, quit, NULL);
  106.     qdevice(WINQUIT);
  107.     add_event(ANY, WINSHUT, snurb_window, quit, NULL);
  108.     qdevice(WINSHUT);
  109.  
  110.  
  111.     /* window redraw events */
  112.     add_event(ANY, REDRAW, snurb_window, redraw, 0);
  113.     qdevice(REDRAW);
  114.  
  115.     add_event(snurb_window,  LEFTMOUSE, UP, process_left_up, NULL);
  116.     add_event(snurb_window,  LEFTMOUSE, DOWN, process_left_down, NULL);
  117.     qdevice(LEFTMOUSE);
  118.  
  119.     add_event(snurb_window,  MIDDLEMOUSE, UP, process_middle_up, NULL);
  120.     add_event(snurb_window,  MIDDLEMOUSE, DOWN, process_middle_down, NULL);
  121.     qdevice(MIDDLEMOUSE);
  122.  
  123.     add_event(snurb_window,  MOUSEX, ANY, process_mouse_motion, NULL);
  124.     add_event(snurb_window,  MOUSEY, ANY, process_mouse_motion, NULL); 
  125. }
  126.  
  127.  
  128.  
  129. /*
  130.  * Called by the event manager whenever a redraw event occurs,
  131.  * e.g. when the window is resized.
  132.  */
  133. void redraw(void)
  134. {
  135.         getorigin(&origin_x, &origin_y);
  136.         getsize(&size_x, &size_y);
  137.  
  138.         aspect = (float)size_x/(float)size_y;
  139.  
  140.         viewport(0, size_x-1, 0, size_y-1);
  141.  
  142.         draw_display();
  143. }
  144.  
  145.  
  146.  
  147. /*
  148.  * Outta here.
  149.  */
  150. void quit(void)
  151. {
  152.     gexit();
  153.     exit(0);
  154. }
  155.  
  156.  
  157. /* Set initial perspective and viewing */
  158. void set_view(int mode)
  159. {
  160.     if (mode == MVIEWING)
  161.     {
  162.         mmode(MVIEWING); 
  163.         perspective(400, aspect, 1.0, 10.0);
  164.  
  165.         loadmatrix(identity_matrix); 
  166.     }
  167.     else if (mode == MSINGLE)
  168.         perspective(400, aspect, 1.0, 10.0);
  169.  
  170.     translate(0.0, 0.0, -5.0); 
  171.     rotate(450,'x');
  172.     rotate(-450,'y');
  173. }
  174.  
  175.